package com.henry.dicesim;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class DiceSimDemo {

    public static Map<Integer, Integer> getFrequency(Dice dice, int times) {
        Map<Integer, Integer> frequency = new HashMap<>();
        for (int i = 0; i < times; i++) {
            dice.flip();
            int reading = dice.getReading();
            frequency.put(reading, frequency.getOrDefault(reading, 0) + 1);
        }
        return frequency;
    }

    public static void main(String[] args) {
        Dice aDice = new Dice();
        Dice anotherDice = new Dice();

        DiceGame.flipTwice(aDice);
        DiceGame.snakeEyes(aDice, anotherDice);

        int totFlips = 10000;

        Map<Integer, Integer> freq = getFrequency(aDice, totFlips);

        double[] rate = new double[6];
        for (int i = 1; i <= 6; i++) {
            rate[i - 1] = (double) freq.getOrDefault(i, 0) / totFlips;
        }

        System.out.println(Arrays.toString(rate));
    }
}
